package com.maimao.info.service;

import com.baidu.fsg.uid.impl.CachedUidGenerator;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.maimao.core.constant.Constants;
import com.maimao.core.constant.ListData;
import com.maimao.core.constant.RedisKeys;
import com.maimao.core.exception.MaiMaoDaoException;
import com.maimao.core.model.resp.PageResult;
import com.maimao.core.model.resp.Result;
import com.maimao.core.utils.DateUtils;
import com.maimao.core.utils.MapUtils;
import com.maimao.info.client.ShopClient;
import com.maimao.info.mapper.CouponUserMapper;
import com.maimao.info.mapper.RegionMapper;
import com.maimao.mg.repository.MgCouponMapper;
import com.maimao.model.goods.Category;
import com.maimao.model.info.CouponUser;
import com.maimao.model.info.MgCoupon;
import com.maimao.model.info.Region;
import com.maimao.model.info.vo.CouponSearch;
import com.maimao.model.user.Shop;
import com.mongodb.client.result.UpdateResult;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author MaoLin Wang
 * @date 2021/1/5 4:27 下午
 */
@Service
public class RegionService {

    @Autowired
    private RegionMapper regionMapper;
    @Autowired
    private RedisTemplate redisTemplate;

    public List<Region> regionTree() {
        List<Region> regionsTree = (List<Region>) redisTemplate.opsForValue().get(RedisKeys.REGION_TREE);
        if (regionsTree == null || regionsTree.size() <= 0) {
            regionsTree = regionMapper.treeData(0);
            redisTemplate.delete(RedisKeys.REGION_TREE);
//            总是push了double数据不知道为啥？？？？
//            redisTemplate.opsForList().rightPushAll(RedisKeys.REGION_TREE,regionsTree);
            redisTemplate.opsForValue().set(RedisKeys.REGION_TREE, regionsTree);
        }
        return regionsTree;
    }


}
